########################### wac ###########################

function cf_wac_pushf() {
  local server_url="http://uav.wacai.info/api/v2/file/upload"

  if [ $# -ne 1 ]; then
    echo "Just need file path, please." && return 1
  fi

  if [ ! -f "$1" ]; then
    echo "$1 Not a file." && return 1
  fi

  local url_s symlink
  url_s=$(curl -X POST -F file=@"$1" --progress-bar $server_url)
  symlink=$(echo "$url_s" | awk -F/ '{print $NF}')
  echo "该文件会保存7天，可以通过如下两种方式下载："
  echo "服务器的命令行: cf_wac_pullf $symlink"
  echo "浏览器下载: $url_s"
}

function cf_wac_pullf() {
  local server_url="http://uav.wacai.info"

  if [ $# -ne 1 ]; then
    echo "Need file code, please." && return 1
  fi

  local url="$server_url/api/v2/file/s/$1"
  local download_url filename
  download_url=$(curl -s "$url")
  filename=$(curl -sI "$download_url" | grep -o -E 'filename=.*$' | sed -e 's/filename=//' | tr -d '\r')
  curl -sS -o "$filename" "$download_url"
  echo "Save to $filename"
}
